package com.ice.payment.controller;

import com.ice.payment.entity.Product;
import com.ice.payment.service.ProductService;
import com.ice.payment.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * CrossOrigin 开放前段跨域访问
 *
 * @author icewinters
 */
@CrossOrigin
@Api(tags = "商品管理")
@RestController
@RequestMapping("/api/product")
public class ProductController {

    @Resource
    private ProductService productService;

    @ApiOperation("测试接口")
    @GetMapping("/test")
    public R test() {
        return R.ok().data("time", new Date()).data("msg", "ice-winters");
    }

    @GetMapping("/list")
    public R list() {
        List<Product> products = productService.list();
        return R.ok().data("products", products);
    }

}
